package com.west_traveler.ximalayafm.category_activity;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;

import com.west_traveler.application.BaseApplication;
import com.west_traveler.entity.entity_category.entity_category_second.Entity_Cate_Fra;
import com.west_traveler.entity.entity_category.entity_category_second.Entity_Cate_Fra_tag_en;
import com.west_traveler.find_page_fragment.cate_fragment.Cate_FraPagerAdapter;
import com.west_traveler.inteface.HttpService;
import com.west_traveler.ximalayafm.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class Category_Activity extends AppCompatActivity implements Callback<Entity_Cate_Fra> {

    private Toolbar toolar;
    private TabLayout tablayout;
    private ViewPager pager;
    private Intent intent;
    private int categoryId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category_);
        intent = getIntent();
        categoryId = intent.getIntExtra("categoryId", 3);
        initView();
        aboutToolbar();
        //数据源
        BaseApplication application = (BaseApplication) getApplication();
        HttpService service = application.getService();
        service.getEntity_Cate_Fra(categoryId,"album","android","5.4.3").enqueue(this);

    }

    private void aboutToolbar() {
        String title = intent.getStringExtra("title");
        toolar.setTitle(title);
    }
    private void initView() {
        toolar = (Toolbar) findViewById(R.id.toolbar_cate_id);
        tablayout = (TabLayout) findViewById(R.id.tl_cate_id);
        pager = (ViewPager) findViewById(R.id.vp_cate_id);

    }

    @Override
    public void onResponse(Call<Entity_Cate_Fra> call, Response<Entity_Cate_Fra> response) {
        Entity_Cate_Fra body = response.body();
        Cate_FraPagerAdapter adapter = new Cate_FraPagerAdapter(getSupportFragmentManager(),body);
        pager.setAdapter(adapter);
        tablayout.setupWithViewPager(pager);

    }

    @Override
    public void onFailure(Call<Entity_Cate_Fra> call, Throwable t) {
        Toast.makeText(this, "数据加载失败。。耨", Toast.LENGTH_LONG).show();
    }
}
